import { OnChanges } from '@angular/core/src/metadata/lifecycle_hooks';
// import { SelectComponent } from './../select/select.component';
import { Component, OnInit, EventEmitter, Output, Input } from '@angular/core';
import { SelectComponent } from '../select/select.component';

@Component({
  selector: 'min-option',
  templateUrl: './option.component.html',
  styleUrls: ['./option.component.less']
})
export class OptionComponent implements OnInit {

  constructor(private parent:SelectComponent) { }
  @Input() key: any = null;
  @Input() lable: any = null;
  @Output() selected: EventEmitter<any> = new EventEmitter();
  

  ngOnInit() {
    this.parent.lableSwitch.subscribe(data=>{
      if(data !== undefined && data !== null){
        if(data == this.key){
          this.parent.seletedData = this.lable;
        }
      }
      if(data === ''){
        this.parent.seletedData = this.lable = '';
      }
    })
  }

  selectData(item) {
    event.stopPropagation();
    this.parent.isOption = false;
    this.parent.seletedData = item.target.innerText;
    this.parent.onModelChange(this.key);
  }
}
